<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Index extends MY_Controller {

    
    public function __construct()
    {
        parent::__construct();
        parent::_get_jscript(__FILE__);
    }

    public function index()
    {
        if ($this->tank_auth->is_logged_in())
        {
			$data['user_id']	= $this->tank_auth->get_user_id();
			$data['user_login']	= $this->tank_auth->get_username();
		
        
            $user_obj       = $this->em->find( 'models\User', $this->tank_auth->get_user_id() );
        
            if ($user_obj->getProspectus())
            {
                $this->smarty->assign("has_prospectus", true);
                $prospectus_obj = $this->em->find( 'models\Prospectus', $user_obj->getProspectus()->getProspectusId() );
                $subject_objs   = $this->em->getRepository( 'models\Subject' )->findBy( array( 'prospectus_id' => $prospectus_obj->getProspectusId() ) );
        
                $subject_array = array();
                foreach($subject_objs as $subject_obj)
                {
                    $semester_obj = $subject_obj->getSemester();
                    $subject_array[$semester_obj->getSemesterYear() . " " . $semester_obj->getSemesterName()][] = $subject_obj;
                }
        
                $this->smarty->assign("subject_array", $subject_array);
            }
        }
        
        // TODO: Move these variables to a config file
        $data['page_title'] = 'Index page';
        
        // Load the template from the views directory
        $this->smarty->view("index.tpl", $data);
    }

}
